﻿using System;
using System.Windows.Forms;

using SharedGenomics.Core;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public class MenuBarMenu : ToolStripMenuItem, IMenuBarMenu
    {
        public void AddSubMenu(IMenuBarMenu subMenu)
        {
            ToolStripMenuItem menuItem = subMenu as ToolStripMenuItem;
            menuItem.ThrowIfNull<ArgumentException>("Invalid sub menu type - expected System.Windows.Forms.ToolStripMenuItem");

            this.DropDownItems.Add(menuItem);
        }

        public ICommand Command { get; set; }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            if (this.Command != null)
            {
                this.Command.Execute();
            }
        }
    }
}
